package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.oocl.dao.pojo.Book;

import util.DBUtil;

public class AddBookThread implements Runnable {
	private Book b;

	public AddBookThread(Book b) {
		super();
		this.b = b;
	}

	
	public Book getB() {
		return b;
	}


	public void setB(Book b) {
		this.b = b;
	}


	public void run() {

		String sql = "insert into book(id,bname,pub_date,author,price,is_new,publisher) values (?,?,?,?,?,?,?)";
		PreparedStatement pst = null;
		Connection con = null;
		int m = 0;
		try {
			con = DBUtil.createConnectionWitDatasource();
			pst = con.prepareStatement(sql);
			pst.setInt(1, b.getId());
			pst.setString(2, b.getName());
			pst.setDate(3, new java.sql.Date(b.getPubDate().getTime()));
			pst.setString(4, b.getAuthor());
			pst.setDouble(5, b.getPrice());
			pst.setBoolean(6, b.isNew());
			pst.setString(7, b.getPublisher());
			m = pst.executeUpdate(); // 返回值为语句执行后影响的数据库中数据条数
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(con, pst, null);
		}

	}

}
